Enhance SQL keyword detection in bracket matcher#535
Conversation
|
I am seeing two issues:
I am debugging now and will report my results and a likely fix if I can find it.
|
The isVariableContext() function was incorrectly treating ALL keywords
followed by '(' as variables, which broke normal control flow statements
like if (condition), dou (condition), and elseif (condition).
This fix now only treats a keyword followed by '(' as a variable if it's
also preceded by operators like '.', '(', or ',' that indicate it's being
used as a value in an expression.
Examples that now work correctly:
- if (condition) → KEYWORD (control flow)
- foo(end) → VARIABLE (end is function parameter)
- arr(if) → VARIABLE (if is array subscript)
- ds.end(x) → VARIABLE (end is DS field)
Fixes the ENDIF/ENDDO/ELSE highlighting errors in debug mode.
bobcozzi
left a comment
There was a problem hiding this comment.
Summary of Bug Fixes for PR 535
I've identified and fixed a critical bug that was causing ENDIF, ENDDO, ELSE, and ELSEIF statements to be incorrectly flagged with red error highlights in debug mode.
Root Cause
The isVariableContext() function in both bracketMatcher.ts and blockParser.ts was treating ALL keywords followed by ( as variables. This broke normal control flow statements like:
if (condition)dou (condition)elseif (condition)
When these keywords were incorrectly marked as variables, they weren't added to the block stack, causing their corresponding closing statements (ENDIF, ENDDO, ELSE) to have no matching opening keywords - resulting in red error highlights.
Fix Applied
Modified the isVariableContext() function to only treat a keyword followed by ( as a variable if it's also preceded by operators that indicate it's being used as a value in an expression (., (, ,, etc.).
Examples that now work correctly:
if (condition)→ KEYWORD (control flow) - no preceding operatorfoo(end)→ VARIABLE (function parameter) - preceded by(arr(if)→ VARIABLE (array subscript) - preceded by(ds.end(x)→ VARIABLE (data structure field) - preceded by.
Files Modified
extension/client/src/language/bracketMatcher.ts- UpdatedisVariableContext()logiclanguage/utils/blockParser.ts- UpdatedisVariableContext()logictests/suite/bracketValidation.test.ts- Updated test cases
Testing
Verified the fix resolves the debug mode highlighting issue:
- Control flow keywords (
if,dou,elseif) followed by(are now correctly identified as keywords - Their corresponding closing statements (
ENDIF,ENDDO,ELSE) no longer show red error highlights - Variables named with keywords in expression contexts still work correctly
The changes have been tested and pushed to the pr-535 branch.
|
Does this resolve issue #534 ? |
Changes
This PR improves the search for keywords that also manage blocks within SQL statements and excludes them from the analysis.
How to test
Open an RPG source file containing SQL statements with keywords such as IF, and verify that the closing keywords of the block are not highlighted in red
Checklist